<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>

</head>
<body>
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <div class="layui-row">
        <form class="layui-form" lay-filter="myform" id="myform">
          <input type="reset" id="btReset" class="layui-hide" >
          <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
              <input type="text" name="name" id="name"  autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">科目</label>
            <div class="layui-input-inline">
              <input type="text" id="categoryName" name="categoryName" autocomplete="off" class="layui-input" select>
              <input type="hidden" id="categoryId" name="categoryId">
            </div>
            <label class="layui-form-label">学期学年</label>
            <div class="layui-input-inline">
              <select name="gradeYear" id="gradeYear"></select>
            </div>

          </div>
          <div class="layui-form-item" style="text-align: center">
            <div class="layui-inline">
              <div class="layui-btn-group">
                <button type="button" class="layui-btn layui-btn-primary" data-type="query"><i class="layui-icon">&#xe615;</i>查询</button>
                <button type="button" class="layui-btn layui-btn-primary" data-type="resetBtn"><i class="layui-icon">&#xe669;</i>重置</button>
              </div>
            </div>
          </div>
        </form>
      </div>
      <div class="row">
        <table class="layui-hide"  id="main-table" lay-filter="main-table"></table>
      </div>
    </div>
  </div>
</div>

<script th:inline="none"></script>
<script>
  let userId = `[[${session.me.id}]]`;
  let roleCode = (`[[${session.me.roleCode}]]`);
  layui.link('layuiadmin/plugins/layui_complete-master/autocomplete.css');
  layui.extend({
    autocomplete: '{/}layuiadmin/plugins/layui_complete-master/autocomplete'
  });
  layui.use(['table','form','autocomplete'], function(){
    var table = layui.table,
            autocomplete = layui.autocomplete,
            form = layui.form;
    select('gradeYear/getPageList?limit=30&page=1' , 'gradeYear',form,'name','id')
    setAutocomplete('libCategory/getPageList?page=1&limit=20',autocomplete,"categoryName",'{{d.name}}','{{d.name}}',"setMajor");
    window.setMajor = function(data){
      $("#categoryId").val(data.id);
      $("#categoryName").val(data.name);
    }
    table.render({
      elem: '#main-table'
      ,height: (top.height-85)+'px'
      ,url: 'paper/getPageList'
      ,title: '试卷列表'
      ,page: true
      ,where:{state:2}
      ,toolbar: '#toolbarPrice'
      ,cols: [
        [
          {type: 'checkbox'}
          ,{type: 'numbers'}
          ,{field: 'name', title: "试卷名称",width:220,templet:function(d){
            if(roleCode.indexOf("admin")==-1){
              return d.name;
            }else{
              return "<a class='colum-link' href='javascript:void(0)' onclick='viewPaper(\""+d.id+"\")'>" + d.name + "</a>";
            }

          }}
          ,{field: 'code',title: "编号",width:90}
          ,{field: 'majorName',title: "考试专业",width:120}
          ,{field: 'categoryName',title: "考试科目",width:150}

          ,{field: 'studentTypeTxt',title: "学生类型",width:90}
          ,{field: 'paperTypeTxt',title: "A/B/C卷",width:90}
          ,{field: 'testPhaseTxt',title: "考试阶段",width:90}
          ,{field: 'testTypeTxt',title: "考试方式",width:90}
          ,{field: 'lgTxt',title: "试卷语言",width:90}
          ,{field: 'stateTxt',title: "记录状态",width:90}
          ,{field: 'howlong',title: "考试时长",width:90}
          ,{field: 'gradeName',title: "考生年级",width:90}
          ,{field: 'majorName',title: "学年学期",width:180,templet:function (d){
            return d.gradeYearName + d.semesterTxt;
          }}
          ,{field: 'score1',title: "每道单选分",width:100}
          ,{field: 'score2',title: "每道多选分",width:100}
          ,{field: 'score3',title: "每道判断分",width:100}
          ,{field: 'score4',title: "每道简单分",width:100}
          ,{field: 'score5',title: "每道计算分析分",width:120}
          ,{field: 'createTime', title: "登记时间",width:170}
        ]
      ]
      ,done:function(){
        if(roleCode.indexOf("admin")==-1){
          $("button[lay-event!=mock]").hide();
        }
        enableRowClick(table,form,'main-table',"main-table");
      }
    });
    //头工具栏事件
    table.on('toolbar(main-table)', function(obj){
      var checkStatus = table.checkStatus(obj.config.id);
      switch(obj.event){
        case 'viewQuestion':
          var data = checkStatus.data;
          if(data.length===0){
            return layer.msg("请选择记录")
          }
          queryQuestion(data[0].id);
          break;
        case 'word':
          var data = checkStatus.data;
          if(data.length===0){
            return layer.msg("请选择试卷")
          }
          $("#hideForm2").empty().append($("<input type='text' name='paperId'>").val(data[0].id+""));
          $("#hideForm2").attr("action","wordPaper/export").submit();
          break;
        case 'word2':
          var data = checkStatus.data;
          if(data.length===0){
            return layer.msg("请选择试卷")
          }
          $("#hideForm2").empty().append($("<input type='text' name='paperId'>").val(data[0].id+"")).append($("<input type='text' name='hasAnswer'>").val(1));
          $("#hideForm2").attr("action","wordPaper/export").submit();
          break;
      };
    });
    var $ = layui.$, active = {
      query: function(){

        table.reload("main-table",{where:{name:$("#name").val(),gradeYear:$("#gradeYear").val()
            ,difficulty:$("#difficulty").val(),categoryId:$("#categoryId").val()
          }})
      },
      resetBtn:function () {
        $("#btReset").click();

      }
    };
    window.loadGrid = function(tableName){
      table.reload(tableName);
    }
    window.closeWin = function (name){
      top.layer.closeAll();
    }
    $('.layui-form .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

  });
  window.queryQuestion=function (id){
    layer.open({
      id:"openwin",
      type: 2,
      title:'查看试题',
      area:['1500px','750px'],
      content:  "rooter?url=ksxt/paper/question-list&paperId="+id,
      btn:['关闭']
    });
  }
  function edit(id){
    layer.open({
      id:"openwin",
      type: 2,
      title:'修改试卷信息',
      area:['1000px','650px'],
      content:  'rooter?url=ksxt/paper/edit-paper&id='+id,
      btn:['保存','关闭'],
      yes:function(index,layero){
        var dataForm = layer.getChildFrame('form', index);
        dataForm.find("#submitBtn").click();
        return false
      }
    });
  }
  function viewPaper(paperid){
    queryQuestion(paperid);
  }

</script>
<script type="text/html" id="toolbarPrice">
  <div class="layui-btn-group">
    <button class="layui-btn layui-btn-sm" lay-event="viewQuestion"><i class="layui-icon layui-icon-layer"></i>查看试题</button>
    <button class="layui-btn layui-btn-sm" lay-event="word"><i class="layui-icon layui-icon-file"></i>导出</button>
    <button class="layui-btn layui-btn-sm" lay-event="word2"><i class="layui-icon layui-icon-file"></i>导出2</button>
  </div>
</script>
</body>
</html>